home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 312_01 / cf2mak.awk < prev    next >
Text File  |  1990-04-21  |  15KB  |  331 lines

  1. #  HEADER:        ;
  2. #  TITLE:         Intel Bind (Link) Configuration file object file extractor
  3. #  DATE:          09/20/1989;
  4. #  VERSION:       1.8;
  5. #  DESCRIPTION:   "An AWK program which scans a bind-configuration
  6. #                 file and builds a batch file which will in turn
  7. #                 produce a make-file.  Requires the services of a
  8. #                 source-file dependency generator (such as cincdep)."
  9. #  KEYWORDS:      Makefile, make, include, dependency generator;
  10. #  SYSTEM:        MS-DOS;
  11. #  WARNINGS:      "Your CF file must contain all of the object files which
  12. #                 you want scanned.  PolyAwk will generate false matches
  13. #                 to lines beginning with non-ASCII (i.e. 128..256) chars."
  14. #  FILENAME:      CF2MAK.AWK;
  15. #  SEE-ALSO:      CINCDEP.AWK, TLR2MAK.AWK, AINCDEP.AWK, PINCDEP.AWK;
  16. #  AUTHORS:       James Yehle;
  17. #  COMPILERS:     PolyAWK, Mortice Kern AWK, Rob Duff's PC-AWK 2.0;
  18. #
  19. #-----------------------------------------------------------------------------
  20. #
  21. #  Cf2mak.awk              Last modified  Sep 20, 1989  13:03
  22. #
  23. #     Scans an Intel bind configuration file to produce a batch file
  24. #     which will call dependency generator(s) to build a set of
  25. #     make-file dependency lists, and eventually a full make-file.
  26. #
  27. #  Jim Yehle
  28. #
  29. # . . . Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . .
  30. #
  31. #  1.8  Sep 19 89         JRY  Added target-file, i.e. "object(name)", name
  32. #                               extractor.. uses iRMX default if absent.
  33. #  1.7  Sep 10 89         JRY  Added legal-filename-char regular expression
  34. #  1.6  Aug 28 89         JRY  Added "verbose" CO output as debug level 1.
  35. #  1.5  Jul 24 89         JRY  Removed source & include pathnames from command-
  36. #                               line (it was getting too long for in DOS) and
  37. #                               made them into internal variables.  Added ASM
  38. #                               and PL/M source/include pathnames (which defi-
  39. #                               nitely wouldn't have fit onto the command line),
  40. #                               along with code to call those two languages'
  41. #                               dependency generators.  Expanded "cc" & "ccf"
  42. #                               to support multiple languages, not just C.
  43. #                               removed them from command-line as well.
  44. #  1.4  Jun 20 89         JRY  Added "lcf=" and "ccf=" command-line parameters 
  45. #  1.3  Jun 7  89         JRY  Added "incpath=", "cc=" & "cl=" command-line
  46. #                               parameters (and get_cl_param() to handle 'em)
  47. #  1.2  May 30 89         JRY  Added "srcpath=" command-line parameter,
  48. #                               added executable-file dependency list to top
  49. #                               of depencency-file (outfile)
  50. #  1.1  Cinco di Mayo 89  JRY  Closed file after checking if it exists
  51. #  1.0  Apr 21 89         JRY  Initial creation
  52. # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  53. #
  54. #  Usage is:
  55. #    awk -f cf2mak.awk filename.cf outfile=[path]filename
  56. #        lc=command lcf=[p][n][e] [>batchfile]
  57. #     where outfile gets the conglomerated dependency generators' output
  58. #     Order of command-line parameters (save for "-f ..." 
  59. #      and ">batchfile") is irrelevant, but identifiers must be in lower case.
  60. #     lc is the compile command (no spaces allowed)
  61. #     lcf controls which components of the source file's name get
  62. #         included in the link command line: p = directory path,
  63. #         n = name, e = extension.
  64. # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  65. #
  66. #  Takes an Intel bind configuration file as input.
  67. #  Generates an executable-dependency list at the start of outfile,
  68. #  followed by the link command and the primary (executable) file name.
  69. #  Extracts all "filename.obj" file names.
  70. #  Generates a batch file line, for each object file found, of the form:
  71. #   comdpre srcfile "incpath="incpath "objname="file.obj
  72. #     "cc="cc "ccf="ccf comdmid outfile comdpost
  73. #  unless the source file can't be found, in which case it makes this batch file line:
  74. #   comdpre "__NOFILE__ objname="file.obj "cc= ccf= " comdmid outfile comdpost
  75. #  The search for the source file covers C, assembly, and PL/M path and extensions.
  76. #
  77. #-----------------------------------------------------------------------------
  78. #
  79. BEGIN {
  80.    # Set various strings used in building batch-file command lines
  81.  
  82.    #  Cf2mak supports several languages.  Each language must have
  83.    #   1) a source file name extension (to replace ".obj" in searches)
  84.    #   2) a source directory pathname (stuck on front of file name during search)
  85.    #   3) an include-file directory whose name to pass to a dependency scanner
  86.    #   4) a compiler command to pass to dependency scanner (no spaces allowed)
  87.    #   5) controls for filename pathname/extension inclusion in compile command line
  88.    #   6) a dependency generator awk program
  89.  
  90. # ------------- User-customized section ------------------------------
  91.    # Language 1 is C
  92.    ext[1] = ".c"
  93.    path[1]    = "s:\\c\\"
  94.    ipath[1]   = "s:\\c\\inc\\"
  95.    cc[1] = "ccd"
  96.    ccf[1] = "n"
  97.    depgen[1] = "d:\\source\\awk\\cincdep.awk"
  98.    # Language 2 is PL/M
  99.    ext[2] = ".plm"
  100.    path[2]  = "s:\\plm\\"
  101.    ipath[2] = "s:\\plm\\inc\\"
  102.    cc[2] = "plmld"
  103.    ccf[2] = "n"
  104.    depgen[2] = "d:\\source\\awk\\pincdep.awk"
  105.    # Language 3 is assembly
  106.    ext[3] = ".a28"
  107.    path[3]  = "s:\\asm\\"
  108.    ipath[3] = "s:\\asm\\inc\\"
  109.    cc[3] = "asm"
  110.    ccf[3] = "n"
  111.    depgen[3] = "d:\\source\\awk\\aincdep.awk"
  112.  
  113.    #    allpre      Leading line(s) of entire batch file
  114.    #    allpost     Trailing line(s) of entire batch file
  115.    #    comment     Comment-line lead-in: DOS "REM" or "ECHO", iRMX ";"
  116.    #    comdpre     Command line prefix
  117.    #    comdmid     Command line midle: between source & output file names
  118.    #    comdpost    Command line suffix
  119.    #    exe_ext     Executable file extension (e.g. ".exe" or ".com" for DOS)
  120.    #    linecont    Line-continuation EOL char: snake " /", unix make "\"
  121.    #    fname_chars Regular expression specifying any single legal char
  122.    #                which can appear in a file name.  Must exclude 
  123.    #                directory path separator character! (DOS \, UNIX /)
  124.    allpre = "echo off"
  125.    allpost = "echo on"
  126.    comment = "echo "
  127.    comdpre = "awk -f "
  128.    comdmid = " >>"
  129.    comdpost = ""
  130.    exe_ext = "" 
  131.    linecont = " \\"
  132.    fname_chars = "[^\\\\ :]" # Unix "[^/ ]"; used to use "[A-Za-z0-9_]"
  133. # ------------ End of user-customized section ------------------------
  134. #
  135.    co = "CON"   # Console-out: MS-DOS "CON", iRMX ":co:", unix "/dev/tty"
  136.    debug = 0    # 0=off, 1=verbose, 2=main-level debug, 3= adds functions
  137.  
  138.    print "cf2mak.awk  Bind configuration object-file extractor  v 1.8" > co
  139.  
  140.    outfile = get_cl_param( "outfile=", 0)
  141.    lc = get_cl_param( "lc=", 0)
  142.    lcf = get_cl_param( "lcf=", 0)
  143.  
  144.    print allpre
  145.    if (debug) print allpre >co
  146. }
  147. #
  148. /^[ \t]*[^;&]/ {
  149.    # Strip all comments, i.e. anything after ';' or '&' in a line
  150.    gsub( /[ \t]*[;&].*$/, "")
  151.    for (f = 1; f <= NF; ++f) {
  152.       split( $f, linefields, ",")
  153.       for (j in linefields) {
  154.          if ( linefields[j] ~ /\.[Oo][Bb][Jj]/ ) {
  155.             # Trim all white space from the field
  156.             gsub( /[ \t]/, "", linefields[j])
  157.             # Object file name has been extracted (into linefields[j])
  158.             fullobjname = linefields[j]
  159.             if (debug>1) print "NR " NR ", fullobjname = " fullobjname >co
  160.             # Add object file name to list of 'em
  161.             for (flix=1; flix in flist; flix++)
  162.                ;
  163.             flist[flix] = fullobjname
  164.             # Split object file name into Path, Name & Extension components
  165.             split_filename( linefields[j], objnameparts, fname_chars)
  166.             # Generate one batch file line
  167.             look_for_source_file( objnameparts["name"], fullobjname)
  168.          }
  169.          else if ( linefields[j] ~ /\.[Ll][Ii][Bb]/ ) {
  170.